package com.qingcheng.util.controller;

        import com.aliyun.oss.OSS;
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.web.bind.annotation.CrossOrigin;
        import org.springframework.web.bind.annotation.RequestMapping;
        import org.springframework.web.bind.annotation.RequestParam;
        import org.springframework.web.bind.annotation.RestController;
        import org.springframework.web.multipart.MultipartFile;

        import java.io.IOException;
        import java.util.UUID;

@RestController
@RequestMapping("/upload")
public class UploadController {

    @Autowired
    private OSS ossClient;


    @RequestMapping("/oss")
    public String ossUpload(@RequestParam("file") MultipartFile file, String folder) {

        String bucketName="qingchengtzf";

        // 以时间戳来命名目录

        // 目标文件名
        String fileName= folder +"/" + UUID.randomUUID()+ file.getOriginalFilename();
        try {
            ossClient.putObject(bucketName,fileName,file.getInputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "https://"+bucketName +".oss-cn-shenzhen.aliyuncs.com/"+fileName;
    }
}
